package com.example.springboot.auth.controller;

import com.example.springboot.auth.service.IAuthService;
import com.example.springboot.common.request.LoginRequest;
import com.example.springboot.common.request.RegisterRequest;
import com.example.springboot.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
public class AuthController {

    @Autowired
    private IAuthService authService;

    /**
     * 统一登录接口
     * 所有用户从统一用户表验证身份
     */
    @PostMapping("/login")
    public Result login(@RequestBody LoginRequest loginRequest) {
        return Result.success(authService.login(loginRequest));
    }

    /**
     * 统一注册接口
     * 所有用户注册到统一用户表
     */
    @PostMapping("/register")
    public Result register(@RequestBody RegisterRequest registerRequest) {
        // 直接返回服务层结果
        return authService.register(registerRequest);
    }
    
    /**
     * 统一退出登录接口
     * 提供统一的退出登录API，便于后续扩展
     */
    @PostMapping("/logout")
    public Result logout() {
        return authService.logout();
    }
}